package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import entity.Invitation;
import entity.Page;
import entity.ReplyDetail;
import service.InvitationService;
import service.ReplyDetailService;

@Controller
public class InvitationController {

	@Autowired
	InvitationService invitationService;

	@Autowired
	ReplyDetailService replyDetailService;

	@RequestMapping("/invList")
	public String invList(String title, @RequestParam(defaultValue = "1", required = false) Integer pageNo,
			Model model) {
		Page<Invitation> pageInfo = invitationService.selectPage(title, pageNo);
		model.addAttribute("pageInfo", pageInfo);
		return "invList";
	}

	@RequestMapping("/replyList")
	public String replyList(Integer invid, @RequestParam(defaultValue = "1", required = false) Integer pageNo,
			Model model) {
		Page<ReplyDetail> pageInfo = replyDetailService.selectPage(invid, pageNo);
		model.addAttribute("pageInfo", pageInfo);
		model.addAttribute("invid", invid);
		return "replyList";
	}

	@ResponseBody
	@RequestMapping("delete")
	public Boolean delete(Integer id) {
		return invitationService.delete(id);
	}

	@RequestMapping("toadd")
	public String toadd(Integer invid, Model model) {
		model.addAttribute("invid", invid);
		return "add";
	}

	@ResponseBody
	@RequestMapping("add")
	public Boolean add(ReplyDetail detail) {
		return replyDetailService.add(detail);
	}
}
